package com.lzy.cloud.base.service.impl;

import com.lzy.cloud.base.dto.BaseStructureDto;
import com.lzy.cloud.base.entity.BaseStructure;
import com.lzy.cloud.base.mapper.BaseStructureMapperExt;
import com.lzy.cloud.base.service.StructureService;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StructureServiceImpl implements StructureService {

    @Autowired
    private BaseStructureMapperExt baseStructureMapperExt;

    @Override
    public Long insert(BaseStructureDto baseStructureDto) {
        BaseStructure baseStructure = DozerUtils.map(baseStructureDto, BaseStructure.class);
        return baseStructureMapperExt.insertSelective(baseStructure) > 0 ? baseStructure.getId() : 0;
    }

    @Override
    public int update(BaseStructureDto baseStructureDto) {
        return baseStructureMapperExt.updateByPrimaryKeySelective(DozerUtils.map(baseStructureDto, BaseStructure.class));
    }

    @Override
    public BaseStructureDto findById(Long aLong) {
        return DozerUtils.map(baseStructureMapperExt.selectByPrimaryKey(aLong), BaseStructureDto.class);
    }

    @Override
    public List<BaseStructureDto> getList() {
        return baseStructureMapperExt.getList();
    }

    @Override
    public List<BaseStructureDto> getListByParentId(Long parentId) {
        return baseStructureMapperExt.getListByParentId(parentId);
    }

    @Override
    public int getListCountByParentId(Long parentId) {
        List<BaseStructureDto> baseStructureDtoList = baseStructureMapperExt.getListByParentId(parentId);
        if (null != baseStructureDtoList) {
            return baseStructureDtoList.size();
        } else {
            return 0;
        }
    }

    @Override
    public int deleteById(Long id) {
        return baseStructureMapperExt.deleteById(id);
    }
}
